/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package mx.ipn.escuela.dao;
import java.util.List;
import javax.ejb.Local;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import mx.ipn.escuela.modelo.Materia;

/**
 *
 * @author USUARIO_2
 */
@Stateless
@Local
public class MateriaDao {
    @PersistenceContext
    EntityManager em;

    public List<Materia> lista() {
        Query query = em.createQuery("select a from Materia a");
        return query.getResultList();
    }

    public Materia obtiene(Long id) {
        return em.find(Materia.class, id);
    }

    public Materia crea(Materia materia) {
        em.persist(materia);
        return materia;
    }

    public Materia actualiza(Materia materia) {
        materia = em.merge(materia);
        return materia;
    }

    public void elimina(Long id) {
        Materia materia = em.find(Materia.class, id);
        em.remove(materia);
    }
}
